package com.lantosec.hmrp.core.kit.tree;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.poi.ss.formula.functions.T;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
@NoArgsConstructor
public class TreeNodeVo {
    /**
     * 节点主键
     * 被树的 (default)ExpandedKeys / (default)CheckedKeys / (default)SelectedKeys 属性所用。注意：整个树范围内的所有节点的 key 值不能重复
     */
    protected String key;
    /**
     * 标题
     */
    protected String title;

    protected String value;

    protected Integer serviceLife;
    /**
     * 自定义图标
     */
    protected String icon;
    /**
     * 设置为叶子节点
     */
    protected boolean isLeaf;
    /**
     * 其它属性
     */
    protected Map<String, Object> options;

    protected List<T> list;

    /**
     * 统计部门岗位数 岗位下的人员数
     */
    protected Integer sum;

    /**
     * 子节点
     */
    protected List<TreeNodeVo> children;


    public TreeNodeVo(String key, String title) {
        this.key = key;
        this.title = title;
    }

    public TreeNodeVo(String key, List list) {
        this.key = key;
        this.list = list;
    }

    //增加参数value，为了前端渲染下拉树
    public TreeNodeVo(String key, String title,String value) {
        this.key = key;
        this.title = title;
        this.value = value;
    }

    //增加参数list，为了返回岗位下的人数
    public TreeNodeVo(String key, String title,String value,Integer sum) {
        this.key = key;
        this.title = title;
        this.value = value;
        this.sum = sum;
    }

    public TreeNodeVo(String key, String title,Integer serviceLife) {
        this.key = key;
        this.title = title;
        this.serviceLife = serviceLife;
    }

    public TreeNodeVo(String key, String title, boolean isLeaf) {
        this.key = key;
        this.title = title;
        this.isLeaf = isLeaf;
    }

    public TreeNodeVo(String key, String title, List<TreeNodeVo> children) {
        this.key = key;
        this.title = title;
        this.children = children;
        if (children != null && children.size()>0){
            this.isLeaf = false;
        }
    }

    public void insertOptions(String key, Object value) {
        if (options == null) {
            options = new HashMap<String, Object>();
        }
        options.put(key, value);
    }
}
